import java.util.Scanner;

public class demo06 {
    public static int count=0;
    public static int max=0;
    public static int[] dx={0,1,0,-1};
    public static int[] dy={1,0,-1,0};
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int[][] arr=new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j]=sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                count=0;
                dfs(arr,i,j,1);
                if(max<count){
                    max=count;
                }
            }
        }
        System.out.println(max);
    }
    public static void dfs(int[][] arr,int i,int j,int len){
        if(count<len){
            count=len;
        }
        for (int k = 0; k < 4; k++) {
            int x=i+dx[k];
            int y=j+dy[k];
            if((x>=0&&x<arr.length)&&(y>=0&&y<arr[0].length)&&(arr[x][y]<arr[i][j])){
                len++;
                dfs(arr,x,y,len);
                len--;
            }
        }
    }
}
